<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>ModbusPal</title>
    <link rel="stylesheet" type="text/css" href="styles.css" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>

      <h1>How to use Python scripts?</h1>

      <h2>Script Manager</h2>

      <p>To open the Script Manager, click on the <q>Script</q> button in the
      main interface.
      <img src="img/view_of_script_manager_dialog.jpg" class="img-stand-alone" alt="View of the Script Manager dialog" />
      </p>

      <h3>Adding a new script</h3>

      <p>Click on the <q>Add</q> button, and browse the filesystem to select
          of script file. Python scripts should have the <q>.py</q> extension.</p>

      <p>When the script is added to the project, a new entry appears in the
          Script Manager:
      <img src="img/a_script_into_the_script_manager.jpg" class="img-stand-alone" alt="A script added into the script manager" />
      </p>

      <h3>Executing a script</h3>

      <p>Click on the <q>Execute</q> button of a script in order to execute it.</p>

      <h3>Removing a script</h3>

      <p>Click on the <q>Delete</q> button of a script in order to remove it
      from the project.</p>

      <h3>Opening a script</h3>

      <p>Click on the <q>Open</q> button of a script in order to open it into
      the editor defined by the system for Python scripts.</p>

      <h2>Script execution classes</h2>

      <p>Each script has an <q>execution class</q>, which defines when the script
          should be executed. The classes are:</p>

      <dl>
          <dt>On demand</dt>
          <dd>A script with the <q>On demand</q> attribute is not executed
          automatically by ModbusPal. The user has to click on the <q>Execute</q>
          button of this script.</dd>
          <dt>Before init</dt>
          <dd>A script with the <q>Before init</q> attribute will be automatically
          executed when the project is loaded, right before the MODBUS slaves
          and automations information are processed. Examples of scripts that
          should be executed <q>before init</q> are: scripts registering new
          generators, bindings, functions.</dd>
          <dt>After init</dt>
          <dd>A script with the <q>After init</q> attribute will be automatically
          executed when the project is loaded, only after the MODBUS slaves
          and automations information have been processed. Examples of scripts that
          should be executed <q>after init</q> are: scripts creating a user
          interface.</dd>
      </dl>

      <h2>Example</h2>

      <div class="code-sample">
          <a href="py/HelloWorldFrame.py">HelloWorldFrame.py</a>
      <pre>
from javax.swing import *
from java.awt import *

class HelloWorldFrame(JFrame):

  def buttonPushed(self,event):

    self.setVisible(False);

  def __init__(self):

    self.setTitle("Hello world");
    self.setSize(300, 100);
    self.setLayout(BorderLayout());
    self.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    # create the Label
    self.label = JLabel('Hello, world !');
    self.add(self.label, BorderLayout.CENTER);

    # create the button
    self.button = JButton('OK',actionPerformed=self.buttonPushed);
    self.add(self.button, BorderLayout.SOUTH);

# Create the Hello world frame:
frame = HelloWorldFrame();

# Make it visible:
frame.setVisible(True);

# Make it the top window:
frame.toFront();
      </pre>
      </div>

      <h2>Special variables</h2>

      <dl>
          <dt>ModbusPal</dt>
          <dd>Instance of the current ModbusPalProject java class.</dd>
          <dt>mbp_script_path</dt>
          <dd>A String containing the complete pathname of the current script file. Ex: "C:/directory/script.py"</dd>
          <dt>mbp_script_directory</dt>
          <dd>A String containing only the path of the current script file. Ex: "C:/directory"</dd>
          <dt>mbp_script_file</dt>
          <dd>A String containing only the name of the current script file. Ex: "script.py"</dd>
      </dl>

      <h2>API</h2>

      <p>Please consult the Javadoc of ModbusPal in order to get more
      information on all the classes introduced in this page.</p>

  </body>
</html>
